﻿using Microsoft.AspNetCore.Http;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Zdap.Common;

namespace Zdap.XCode.Service
{
    /// <summary>
    ///
    /// </summary>
    /// <typeparam name="TDto"></typeparam>
    public interface IServiceBase<TDto> : IServiceFind<TDto> where TDto : class
    {
        /// <summary>
        /// 保存对象（包含新增和修改）功能
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        ValueTask<ResponseContext<long>> Save(TDto dto, UserTicket user);

        /// <summary>
        /// 批量保存，返回 Id 列表
        /// </summary>
        ValueTask<ResponseContext<List<long>>> BatchSave(SavaListModel<TDto> model, UserTicket currentUser);

        /// <summary>
        /// 批量 List 保存
        /// </summary>
        /// <param name="model"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        ValueTask<ResponseContext<bool>> Saves(SavaListModel<TDto> model, UserTicket currentUser);

        /// <summary>
        /// 批量 Tree List 保存
        /// </summary>
        /// <param name="model"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        ValueTask<ResponseContext<bool>> SaveTreeList(SavaListModel<TreeBaseDto> model, UserTicket currentUser);

        /// <summary>
        /// 单个保存
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        ValueTask<ResponseContext<long>> Add(TDto dto, UserTicket user);

        /// <summary>
        /// 指定更新
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        ValueTask<ResponseContext<bool>> Update(TDto dto, UserTicket user);

        /// <summary>
        /// 根据Id删除
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="user"></param>
        /// <returns></returns>

        ValueTask<ResponseContext<bool>> Delete(long ID, UserTicket user);

        /// <summary>
        /// 根据id 批量删除，修改状态
        /// </summary>
        /// <param name="Ids"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        ValueTask<ResponseContext<bool>> DeleteIds(IEnumerable<long> Ids, UserTicket user);
    }

    /// <summary>
    ///
    /// </summary>
    /// <typeparam name="TDto"></typeparam>
    public interface IServiceFind<TDto> where TDto : class
    {
        /// <summary>查找单行数据</summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        TDto FindByID(long ID);

        /// <summary>
        ///
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        Task<ResponseContext<TDto>> FindById(long Id);

        /// <summary>
        /// 按条件查询 单条信息
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        Task<ResponseContext<TDto>> FindBy(RequestParameter p);

        /// <summary>
        ///
        /// </summary>
        /// <param name="file"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        // ValueTask<bool> ImportDate(IFormFile file, UserTicket user);
        ValueTask<bool> ImportDate<T>(IFormFile file, UserTicket user) where T : class, new();

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        ValueTask<MemoryStream> DownloadTemplate();
    }
}